package com.ag.work.action;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.apache.struts2.interceptor.SessionAware;

import com.ag.bean.TbDisposalAdvice;
import com.ag.bean.TbUser;
import com.ag.common.BaseAction;
import com.ag.common.IPermissionService;
import com.ag.common.PageUtil;
import com.ag.work.service.impl.DisposalStatusServiceImpl;
import com.ag.work.service.impl.MyAdviceServiceImpl;


@SuppressWarnings("serial")
public class MyAdviceAction extends BaseAction implements SessionAware {

	private static final Logger logger = Logger.getLogger(MyAdviceAction.class);
	private MyAdviceServiceImpl myAdviceServiceImpl;
	/**
	 * 调用权限服务逻辑组件
	 */
	@Resource(name = "PermissionServiceImpl")
	private IPermissionService pms;
	private List<TbDisposalAdvice> myAdviceList;
	private List<TbDisposalAdvice> myRequest;
	private String ajaxRST="0";
	private TbDisposalAdvice disposalAdvice = new TbDisposalAdvice();
	private String daId;
	private String daContent;
	private DisposalStatusServiceImpl disposalStatusServiceImpl;
	private PageUtil  pageUtil;
	private int total;
	private int page;
	private int maxRow;
	/**
	 * 提供Map<String, Object>类型的Session变量，用来保存Struts2注入的Session上下文
	 */
	private Map<String, Object> sessionMap;	
	
	public String findMyAdvice() {
		System.out.println("这是findMyAdvice_Action");
		TbUser user = pms.getCurrentUser(sessionMap);
		logger.info("UId:------"+user.getUId());
		String UId = user.getUId();
		try {
			myAdviceList= myAdviceServiceImpl.findMyAdvice(UId);
			//myAdviceList= myAdviceServiceImpl.findMyAdvice("ag");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "myAdvice";
	}
	/**
	 *查找我的处置建议
	 */
	public String findMyAdvice1(){
		TbUser user = pms.getCurrentUser(sessionMap);
		logger.info("UId:------"+user.getUId());
		String UId = user.getUId();
		myAdviceList = myAdviceServiceImpl.findMyAdvice1(UId);

		return "myAdvice1";
	}
	/**
	 *查找我的处置申请
	 */
	public String findMyRequest(){
		TbUser user = pms.getCurrentUser(sessionMap);
		logger.info("UId:------"+user.getUId());
		String UId = user.getUId();
		myRequest = myAdviceServiceImpl.findMyRequest(UId);

		return "myRequest";
	}
	/**
	 *查找我的建议申请有分页功能
	 */
	public String findMyRequestPage(){
		TbUser user = pms.getCurrentUser(sessionMap);
		logger.info("UId:------"+user.getUId());
		String UId = user.getUId();
		pageUtil = myAdviceServiceImpl.findRequestPage(total, page, maxRow, UId);
		return "myRequestPage";
	}
	/**
	 *查找我的处置建议有分页功能
	 */
	public String findMyAdvicePage(){
		TbUser user = pms.getCurrentUser(sessionMap);
		logger.info("UId:------"+user.getUId());
		String UId = user.getUId();
		pageUtil = myAdviceServiceImpl.findAdvicePage(total, page, maxRow, UId);
		return "myAdvicePage";
	}
	/**
	 *将处置申请改为已读未回复 
	 */
	public void changStatusToWh(){
		logger.info("改变为已读未回复！！！");
		TbDisposalAdvice disAdvice = myAdviceServiceImpl.findByDaId(daId);
		disAdvice.setDaAcceptTime(new Date());
		myAdviceServiceImpl.update(disAdvice);
		disposalStatusServiceImpl.changeDispStatus(DisposalStatusServiceImpl.ADVICE_STATUS_YDWH, daId);
	}
	/**
	 *将处置申请改为已回复 
	 */
	public void changStatusToYh(){
		logger.info("改变为已回复！！！");
		logger.info("daId--"+daId);
		logger.info("daContent:--"+daContent);
		TbDisposalAdvice advice = myAdviceServiceImpl.findByDaId(daId);
		advice.setDaContent(daContent);
		advice.setDaSubmitTime(new Date());
		myAdviceServiceImpl.update(advice);
		
		disposalStatusServiceImpl.changeDispStatus(DisposalStatusServiceImpl.ADVICE_STATUS_YDYH, daId);
	}
	/*暂时没用上
	 * public String save() {
		TbUser user = pms.getCurrentUser(sessionMap);
		//String UId = user.getUId();
		//TbUser tbUser = myAdviceServiceImpl.findById(UId);
		TbDisposalAdvice disposalAdvice = new TbDisposalAdvice();
		disposalAdvice.setTbUserByAdviceUId(user);
		logger.info("内容：－－－"+daContent);
		disposalAdvice.setDaContent(daContent);
		this.myAdviceServiceImpl.save(disposalAdvice);
		
		this.ajaxRST="1";
		return "saveOK";
	}*/
	/**
	 *查看事件详情
	 */
	public String findByDaId(){
		logger.info("详情：－－"+daId);
		disposalAdvice = this.myAdviceServiceImpl.findByDaId(daId);
		return "findByIdOK";
	}
	/**
	 *查看事件详情1
	 */
	public String findByDaId1(){
		logger.info("详情1：－－"+daId);
		disposalAdvice = this.myAdviceServiceImpl.findByDaId(daId);
		return "findByIdOK1";
	}


	@Override
	public void setSession(Map<String, Object> session) {
		this.sessionMap = session;
	}

	public List<TbDisposalAdvice> getMyAdviceList() {
		return myAdviceList;
	}

	public void setMyAdviceList(List<TbDisposalAdvice> myAdviceList) {
		this.myAdviceList = myAdviceList;
	}

	public MyAdviceServiceImpl getMyAdviceServiceImpl() {
		return myAdviceServiceImpl;
	}

	public void setMyAdviceServiceImpl(MyAdviceServiceImpl myAdviceServiceImpl) {
		this.myAdviceServiceImpl = myAdviceServiceImpl;
	}

	public String getAjaxRST() {
		return ajaxRST;
	}

	public void setAjaxRST(String ajaxRST) {
		this.ajaxRST = ajaxRST;
	}

	public List<TbDisposalAdvice> getMyRequest() {
		return myRequest;
	}

	public void setMyRequest(List<TbDisposalAdvice> myRequest) {
		this.myRequest = myRequest;
	}

	public String getDaId() {
		return daId;
	}

	public void setDaId(String daId) {
		this.daId = daId;
	}

	public TbDisposalAdvice getDisposalAdvice() {
		return disposalAdvice;
	}

	public void setDisposalAdvice(TbDisposalAdvice disposalAdvice) {
		this.disposalAdvice = disposalAdvice;
	}

	public DisposalStatusServiceImpl getDisposalStatusServiceImpl() {
		return disposalStatusServiceImpl;
	}

	public void setDisposalStatusServiceImpl(
			DisposalStatusServiceImpl disposalStatusServiceImpl) {
		this.disposalStatusServiceImpl = disposalStatusServiceImpl;
	}
	public String getDaContent() {
		return daContent;
	}
	public void setDaContent(String daContent) {
		this.daContent = daContent;
	}
	public PageUtil getPageUtil() {
		return pageUtil;
	}
	public void setPageUtil(PageUtil pageUtil) {
		this.pageUtil = pageUtil;
	}
	public int getTotal() {
		return total;
	}
	public void setTotal(int total) {
		this.total = total;
	}
	public int getPage() {
		return page;
	}
	public void setPage(int page) {
		this.page = page;
	}
	public int getMaxRow() {
		return maxRow;
	}
	public void setMaxRow(int maxRow) {
		this.maxRow = maxRow;
	}

}
